package com.motion.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.motion.generator.entity.Goods;
import com.motion.generator.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {
    @Autowired(required = false)
    GoodsMapper goodsMapper;
    public List<Goods> cheak(Long page, Long size){
        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("goodsId",1);
        List<Goods> ref=goodsMapper.selectPage(new Page<>(page,size),queryWrapper).getRecords();
        return ref;
    }

    public Goods insertGoodsDto(Goods goods){
        goodsMapper.insert(goods);
        return goods;
    }

    public boolean deleteGoods(Long goodsId) {
        goodsMapper.deleteById(goodsId);
        return true;
    }

    public Goods updateGoods(Goods goods){
        goodsMapper.updateById(goods);
        return goodsMapper.selectById(goods);
    }
}
